package main

import (
	"auto-wallpaper/profile"
	"auto-wallpaper/util"
	"auto-wallpaper/wallpaper"
	"auto-wallpaper/win"
	"github.com/getlantern/systray"
	"io"
	"os"
)

func main() {

	systray.Register(onReady, nil)
	win.ConfigureWebview("Auto-Wallpaper", 1024, 768)
}

// 启动任务栏
func onReady() {
	file, _ := os.Open("conf/bitbug_favicon.ico")
	bytes, _ := io.ReadAll(file)
	systray.SetTemplateIcon(bytes, bytes)
	systray.SetTitle("Webview example")
	mShowLantern := systray.AddMenuItem("设置", "")
	refresh := systray.AddMenuItem("更新图库", "")
	refreshLocal := systray.AddMenuItem("刷新本地图片", "")
	mQuit := systray.AddMenuItem("退出程序", "退出程序")
	go func() {
		for {
			select {
			case <-mShowLantern.ClickedCh:
				systray.SetTooltip("不可用")
			case <-refresh.ClickedCh:
				wallpaper.LoadImg()
			case <-refreshLocal.ClickedCh:
				var files, _ = util.ListDir(profile.AppConfigSet.BasePath, "")
				profile.Imgs = &files
			case <-mQuit.ClickedCh:
				systray.Quit()
				os.Exit(1)
			}
		}
	}()

	profile.LoadProfiles()
	// 更新图片
	// 加载配置
	wallpaper.LoadImg()
	// 判断是否需要切换壁纸
	wallpaper.SwitchImg()
}
